﻿using System;

using System.Collections.Generic;
using System.Text;
using Silvermoon.Controls;
using Silvermoon.Controls.Classes;
using Silvermoon.Animations;
using System.Drawing;
using System.Xml;
using System.IO;
using MelectricComponents;

namespace FileExplorer
{
    public class AddExerciseWindow : Window
    {
        private Toolbar toolbar;
        private BackgroundDecorator background;
        private TextBox txtExercise;
        private TextBox txtDateTime;
        private TextBox txtDuration;
        private DropDownButton dropDown;
        public AddExerciseWindow()
            : base()
        {
            this.Flags = ControlFlags.IgnoreChildClipping;
            background = new BackgroundDecorator { Color = System.Drawing.Color.Silver };
            background.Margin = new Margin(0);
            Controls.Add(background);

            txtDateTime = new TextBox
            {
                Alpha = 128
               ,
                ToolTip = new DatePickerToolTip()
               ,
                Size = new Size(Screen.Width, 100)
               ,
                Location = new Point(0, 0)
                ,
                Text = DateTime.Now.ToString("dd/MM/yyyy")
            };
            Controls.Add(txtDateTime);

            txtExercise = new TextBox
                                    {
                                        Alpha = 128
                                        ,
                                        Height = 100
                                        ,
                                        Width = Screen.Size.Width / 8 * 5
                                        ,
                                        Font = new Silvermoon.OpenGL.FontSprite(new Font(FontFamily.GenericSansSerif, 14, FontStyle.Bold))
                                        ,
                                        Location = new Point(0, 100)
                                        ,
                                        Visible=false
                                    };
            Controls.Add(txtExercise);
            dropDown = new DropDownButton { Bounds = new Rectangle(0, 100, Screen.Size.Width / 8 * 5, 100), Text = "Type", Color = Color.Snow, TextColor = Color.Black };
            dropDown.AddItems("Situps", "Pressups", "Cycling", "Walking", "Jogging", "Football", "Other");
            Controls.Add(dropDown);
            dropDown.ItemClicked += new EventHandler<ItemEventArgs>(OnItemClicked);
            Label lblExercise = new Label
                                    {
                                        Text = "Activity"
                                        ,
                                        Alpha = 128
                                        ,
                                        Height = 100
                                        ,
                                        Width = Screen.Size.Width / 8 * 3
                                        ,
                                        Location = new Point(Screen.Size.Width / 8 * 5, 100)
                                        ,
                                        Font = new Silvermoon.OpenGL.FontSprite(new Font(FontFamily.GenericSansSerif, 14, FontStyle.Bold))
                                    };
            Controls.Add(lblExercise);

            txtDuration = new TextBox
            {
                Alpha = 128
                ,
                Height = 100
                ,
                Width = Screen.Size.Width / 8 * 5
                ,
                Font = new Silvermoon.OpenGL.FontSprite(new Font(FontFamily.GenericSansSerif, 14, FontStyle.Bold))
                ,
                Location = new Point(0, 200)
            };
            Controls.Add(txtDuration);
            lblExercise = new Label
            {
                Text = "Time"
                ,
                Alpha = 128
                ,
                Height = 100
                ,
                Width = Screen.Size.Width / 8 * 3
                ,
                Location = new Point(Screen.Size.Width / 8 * 5, 200)
                ,
                Font = new Silvermoon.OpenGL.FontSprite(new Font(FontFamily.GenericSansSerif, 14, FontStyle.Bold))
            };
            Controls.Add(lblExercise);

            toolbar = new Toolbar();
            Toolbar = toolbar;
            toolbar.LeftButton.Text = "Cancel";
            toolbar.RightButton.Text = "Submit";
            toolbar.LeftButton.Click += (s, e) => { Hide(TransitionMode.ZoomOut); dropDown.Visible = true; txtExercise.Visible = false; };
            toolbar.RightButton.Click += (s, e) => { SaveData(); };
        }
        private void SaveData()
        {
            Dictionary<string, string> Attributes = new Dictionary<string, string>();
            Attributes.Add("DateTime", txtDateTime.Text);
            Attributes.Add("Activity", txtExercise.Text);
            Attributes.Add("Duration", txtDuration.Text);
            XMLUtility oXMLUtility = new XMLUtility();
            oXMLUtility.SaveXML("Exercises", "Activity", Attributes);

            string sDuration = txtDuration.Text;
            string sActivity = txtExercise.Text;

            txtDuration.Text = "";
            txtExercise.Text = "";

            ConfirmDialog dlg = new ConfirmDialog("Exercise Complete", sDuration + " x "+ sActivity + " Added", true);
            dlg.Margin = new Margin(0, null, 0, 0);
            dlg.HideTransition = TransitionMode.SwipeOutToBottom;
            dlg.ShowModal(TransitionMode.SwipeInFromBottom, (s, e) =>
            {

                Hide(TransitionMode.ZoomOut);
                dropDown.Visible = true;
                txtExercise.Visible = false;
            });
        }
        protected virtual void OnItemClicked(object sender, ItemEventArgs e)
        {
           // if (ItemClicked != null) dropDown.ItemClicked(this, e);
            MenuItem item = e.Item as MenuItem;
            if (item != null)
            {
                if (item.Text == "Other")
                {
                    dropDown.Visible = false;
                    txtExercise.Text = "";
                    txtExercise.Visible = true;

                }
                else
                {
                    txtExercise.Text = item.Text;
                }


            }

        }
    }
}
